package com.zzh.takeoutapp.adapter;

import android.app.Activity;
import android.support.annotation.Nullable;
import android.support.v4.content.ContextCompat;
import android.support.v7.widget.DefaultItemAnimator;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.StaggeredGridLayoutManager;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Toast;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.zzh.takeoutapp.R;
import com.zzh.takeoutapp.model.ModelUtil;
import com.zzh.takeoutapp.utils.DensityUtil;
import com.zzh.takeoutapp.utils.DividerGridItemDecoration;
import com.zzh.takeoutapp.view.DiscountHeaderBannerView;
import com.zzh.takeoutapp.view.DiscountsView;
import com.zzh.takeoutapp.view.HeaderBannerView;
import com.zzh.takeoutapp.view.stepview.VerticalStepView;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import butterknife.Bind;
import butterknife.ButterKnife;

/**
 * Created by Administrator on 2018/7/24.
 */

public class HomeDiscountAdapter extends BaseQuickAdapter<String, BaseViewHolder> {

    private List<String> flist;
    private int TYPE_TOP0 = 0;//头部布局
    private int TYPE_TOP1 = 1;//头部布局
    private int TYPE_TOP2 = 2;//头部布局
    private int TYPE_TOP3 = 3;//头部布局
    private int TYPE_TOP4 = 4;//头部布局
    private int TYPE_TOP5 = 5;//头部布局
    private int TYPE_TOP6 = 6;//头部布局
    private DiscountHeaderBannerView bannerView;
    private List<String> bannerList = new ArrayList<>(); // 广告数据

    public HomeDiscountAdapter(@Nullable List<String> data) {
        super(R.layout.activity_home_discount, data);
        this.flist = data;
    }

    @Override
    protected BaseViewHolder onCreateDefViewHolder(ViewGroup parent, int viewType) {
        if (viewType == TYPE_TOP0) {
            bannerView = new DiscountHeaderBannerView((Activity) mContext);
            bannerList = ModelUtil.getBannerData();
            return new TypetypeHolder(bannerView.getView(bannerList));
        } else if (viewType == TYPE_TOP1) {
            View views = LayoutInflater.from(mContext).inflate(R.layout.item_home_discount_list_view, parent, false);
            return new TypetyListpeHolder(views);
        } else if (viewType == TYPE_TOP2) {
            View views = LayoutInflater.from(mContext).inflate(R.layout.item_special_offer_layout, parent, false);
            return new TextSpecialOfferHolder(views);
        } else {
            View views = LayoutInflater.from(mContext).inflate(R.layout.item_home_order, parent, false);
            return new TextHolder(views);
        }

    }

    private void initCenterBean(TypetyListpeHolder holder) {
        holder.rvtype.setLayoutManager(new StaggeredGridLayoutManager(2,
                StaggeredGridLayoutManager.VERTICAL));
        List stringList = new ArrayList<>();
        stringList.add("ce测试数据");
        stringList.add("ce测试数据");
        stringList.add("ce测试数据");
        stringList.add("ce测试数据");
        HomeDiscountListAdapter homeDiscountListAdapter = new HomeDiscountListAdapter(stringList);
        holder.rvtype.addItemDecoration(new DividerGridItemDecoration(mContext,
                DensityUtil.px2dip(mContext, 25), R.color.white));
        holder.rvtype.setItemAnimator(new DefaultItemAnimator());
        holder.rvtype.setAdapter(homeDiscountListAdapter);
        homeDiscountListAdapter.setOnItemClickListener(new OnItemClickListener() {
            @Override
            public void onItemClick(BaseQuickAdapter adapter, View view, int position) {
                Toast.makeText(mContext, "", Toast.LENGTH_LONG).show();
            }
        });
    }

    @Override
    public int getItemViewType(int position) {
        if (position == TYPE_TOP0) {
            return TYPE_TOP0;
        }
        if (position == TYPE_TOP1) {
            return TYPE_TOP1;
        }
        if (position == TYPE_TOP2) {
            return TYPE_TOP2;
        } else
            return TYPE_TOP6;
    }

    @Override
    protected void convert(BaseViewHolder helper, String item) {
        if (helper instanceof TypetyListpeHolder) {
            initCenterBean(((TypetyListpeHolder) helper));//加载中间head下面的数据源
        } else if (helper instanceof TextSpecialOfferHolder) {
            List<String> list0 = new ArrayList<String>();
            List<String> list1 = new ArrayList<String>();
            for (int i = 0; i < 5; i++) {
                list0.add("完成数" + i);
            }
            for (int i = 0; i < 10; i++) {
                list1.add("总数" + i);
            }
            ((TextSpecialOfferHolder) helper).verticalStepView.setStepsViewIndicatorComplectingPosition(list0.size() - 1)//设置完成的步数
                    .reverseDraw(false)//default is true
                    .setStepViewTexts(list0, list1)//总步骤
                    .setStepsViewIndicatorCompletedLineColor
                            (ContextCompat.getColor(mContext, R.color.font_black_4))//设置StepsViewIndicator完成线的颜色 white
                    .setStepsViewIndicatorUnCompletedLineColor
                            (ContextCompat.getColor(mContext, R.color.font_black_4))//设置StepsViewIndicator未完成线的颜色 uncompleted_text_color
                    .setStepViewComplectedTextColor
                            (ContextCompat.getColor(mContext, R.color.color_red))//设置StepsView text完成线的颜色 white
                    .setStepViewUnComplectedTextColor
                            (ContextCompat.getColor(mContext, R.color.black))//设置StepsView text未完成线的颜色 uncompleted_text_color
                    .setStepsViewIndicatorCompleteIcon
                            (ContextCompat.getDrawable(mContext, R.drawable.circle_c))//设置StepsViewIndicator CompleteIcon complted
                    .setStepsViewIndicatorDefaultIcon
                            (ContextCompat.getDrawable(mContext, R.drawable.circle_c))//设置StepsViewIndicator DefaultIcon default_icon
                    .setStepsViewIndicatorAttentionIcon
                            (ContextCompat.getDrawable(mContext, R.drawable.circle_r));//设置StepsViewIndicator AttentionIcon attention
        }
    }


    class TextSpecialOfferHolder extends BaseViewHolder {
        @Bind(R.id.step_view)
        VerticalStepView verticalStepView;

        public TextSpecialOfferHolder(View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);
        }
    }

    class TextHolder extends BaseViewHolder {

        public TextHolder(View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);
        }
    }

    class TypetypeHolder extends BaseViewHolder {

        public TypetypeHolder(View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);
        }
    }

    class TypetyListpeHolder extends BaseViewHolder {
        @Bind(R.id.rv_homepageradapter_artist)
        RecyclerView rvtype;

        public TypetyListpeHolder(View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);
        }
    }


}
